﻿using QLBH.DAO;
using QLBH.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QLBH.BLO
{
    class BLO_TPA
    {
        DAO_TPA dao_tpa = new DAO_TPA();
        public int Insert(TPA tpa)
        {
            try
            {
                DataTable idmax = Connection_Sql.GetDatatable("select max(CONVERT(INT, MA_TPA)) from TPA", false);
                int map = 1;
                if (idmax.Rows[0][0].ToString() == "")
                {
                    tpa.Ma_TPA = map.ToString();
                }
                else
                {
                   tpa.Ma_TPA = (int.Parse(idmax.Rows[0][0].ToString()) + 1).ToString();
                }
                return dao_tpa.Insert(tpa);
            }
            catch (System.Exception ex)
            {
                throw new Exception("Lỗi BLO Insert TPA: " + ex.Message);
            }
        }
    }
}
